// When color definition differs for dark and light variant,
// it gets @if ed depending on $variant

$higher_opacity: 0.9;
$middle_opacity: 0.6;
$lower_opacity: 0.3;

$enabled_opacity: 0.75;
$hint_opacity: 0.6;
$disabled_opacity: 0.4;

@function gtkalpha($c, $a) {
  @return unquote("alpha(#{$c}, #{$a})");
}

@function scale-alpha($c, $a) {
  @return scale-color($c, $alpha: percentage(-1 + $a));
}

// based color palette:
// https://material.google.com/style/color.html#color-color-palette
// based border and highlight values:
// https://material.google.com/style/icons.html#icons-product-icons

// Foreground colors
$light_contrast_color: scale-alpha(#000000, 0.8);
$dark_contrast_color: #FFFFFF;
$darker_contrast_color: #E0E0E0;
$darkest_contrast_color: #000000;

$fg_color: if($variant == 'light', $light_contrast_color, $dark_contrast_color);
$secondary_fg_color: scale-alpha($fg_color, $enabled_opacity);
$tertiary_fg_color: scale-alpha($fg_color, $hint_opacity);

$inversed_fg_color: $dark_contrast_color;
$secondary_inversed_fg_color: scale-alpha($inversed_fg_color, $enabled_opacity);
$tertiary_inversed_fg_color: scale-alpha($inversed_fg_color, $hint_opacity);

$disabled_fg_color: scale-alpha($fg_color, $disabled_opacity);
$disabled_secondary_fg_color: scale-alpha($secondary_fg_color, $disabled_opacity);
$disabled_tertiary_fg_color: scale-alpha($tertiary_fg_color, $disabled_opacity);

$disabled_inversed_fg_color: scale-alpha($inversed_fg_color, $disabled_opacity);
$disabled_secondary_inversed_fg_color: scale-alpha($secondary_inversed_fg_color, $disabled_opacity);
$disabled_tertiary_inversed_fg_color: scale-alpha($tertiary_inversed_fg_color, $disabled_opacity);

// Background colors
$bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #333333, #343943), #F5F5F5);
$base_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #404040, #40454F), #FFFFFF);
$alt_base_color: mix($base_color, $bg_color, 50%);

$lighter_bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #444444, #444851), #FAFAFA);
$darker_bg_color: if($variant =='dark', if($color == 'ruby' or $color == 'black' or $color == 'white', #303030, #31353E), #EEEEEE);
$darker_fg_color: if($variant =='light', if($color == 'ruby' or $color == 'black' or $color == 'white', #222222, #191D29), #DDDDDD);

// Headerbar colors
$headerbar_fg_color: if($headerbar =='dark', $dark_contrast_color, $fg_color);
$secondary_headerbar_fg_color: if($headerbar =='dark', $secondary_inversed_fg_color, $secondary_fg_color);
$disabled_headerbar_fg_color: if($headerbar =='dark', $disabled_secondary_inversed_fg_color, $disabled_fg_color);

$headerbar_bg_color: #eeeeee;
@if ($color == 'ruby' or $color == 'black') and $headerbar =='dark' { $headerbar_bg_color: if($variant =='light', #444444, #424242); }
@if ($color == 'doder' or $color == 'beryl') and $headerbar =='dark' { $headerbar_bg_color: if($variant =='light', #444851, #3F444D); }

// Selected and Theme colors
$primary_color: #686868;
$alt_primary_color: #666666;
$accent_color: #666666;
@if $color == 'ruby' { $primary_color: #F0544C; $alt_primary_color: #FF615A; $accent_color: #FF626C; }
@if $color == 'doder' { $primary_color: #4285F4; $alt_primary_color: #03a9f4; $accent_color: #18b8ff; }
@if $color == 'beryl' { $primary_color: #2EB398; $alt_primary_color: #1eba9b; $accent_color: #0fd1ab; }

@if $color == 'black' { 
    $primary_color: if($variant =='light', #686868, rgba($fg_color, 0.35));
    $alt_primary_color: if($variant =='light', #666666, rgba($fg_color, 0.5));
    $accent_color: if($variant =='light', #666666, rgba($fg_color, 1.0)); }

$theme_color: if($color == 'black', $dark_contrast_color, $primary_color);
$alt_theme_color: if($color == 'black', $dark_contrast_color, $accent_color);

$menu_bg_color: if($headerbar =='light', $base_color, $headerbar_bg_color);
$menu_fg_color: if($headerbar =='light', $fg_color, $headerbar_fg_color);
$disabled_menu_fg_color: if($headerbar =='light' and $variant =='light', rgba(#000, 0.5), rgba(#fff, 0.5));

$tab_color: $primary_color;
$secondary_titlebar_color: $primary_color;
$topbar_bg_color: $headerbar_bg_color;
$topbar_fg_color: $headerbar_fg_color;

// Misc colors
$track_color: gtkalpha(currentColor, $lower_opacity);
$semi_track_color: gtkalpha(currentColor, $lower_opacity / 2);
$zero_track_color: gtkalpha(currentColor, 0);
$row_track_color: gtkalpha(currentColor, 0.05);
$borders_color: if($variant == 'light', scale-alpha(#000000, 0.1), scale-alpha(#000000, 0.15));
$highlight_color: if($variant == 'light', scale-alpha(#FFFFFF, 0.4), scale-alpha(#FFFFFF, 0.3));
$secondary_highlight_color: scale-alpha(#FFFFFF, 0.1);

$placeholder_text_color: mix($fg_color, $base_color, percentage($hint_opacity));

$link_color: $primary_color;
$link_visited_color: #E040FB;

$warning_color: #FF6D00;
$error_color: #DD2C00;
$success_color: #00C853;

$suggested_color: #4CAF50;
$destructive_color: #FF5252;

$info_bg_color: #66BB6A;
$question_bg_color: #42A5F5;
$warning_bg_color: #FFA726;
$error_bg_color: #EF5350;

